home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with stringcopy
- Date: 8 Jan 1996 16:24:37 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4crgg5$d71@news.iag.net>
- References: <4clguu$9fs@eagle.novo.dk> <820933963snz@genesis.demon.co.uk> <4cq9dr$if9@ns.RezoNet.NET>
- NNTP-Posting-Host: pm3-orl29.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4cq9dr$if9@ns.RezoNet.NET>, ray@ultimate-tech.com says...
- >
- >In referenced article, Lawrence Kirby says...
- >>Morten Brun writes:
- >>
- >>>How do i do a partial stringcopy i.e. copy from a specific position
- >>>in a string and a certain numbers of bytes. I am looking for a
- >>>function like target = Stringcopy(source, startpos, length)
- >>
- >>target[0] = '\0';
- >>strncat(target, source+startpos, length);
- >
- >...but use strncpy if you are overwriting some existing characters in
- >target and don't want the target string to terminate after the copied
- >characters.
-
- strncpy will append a '\0' to target, when strlen(source+startpos) < length.
- The only way to guarantee that the target won't be terminated by strncpy
- would be some like:
-
- strncat(target, source+startpos, strlen(source+startpos));
-
- or just use memcpy instead. It would probably be faster, since it doesn't
- check for a '\0' in the source.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-